class Solution:
    def firstMissingPositive(self, nums: list) -> int:
        i = 0
        while i < len(nums):
            if nums[i] == i + 1:
                i += 1
                continue
            if nums[i] > len(nums) or nums[i] <= 0:
                i += 1
                continue
            if nums[i] == nums[nums[i] - 1]:
                i += 1
                continue
            temp = nums[nums[i] - 1]
            nums[nums[i] - 1] = nums[i]
            nums[i] = temp

        for i in range(len(nums)):
            if nums[i] != i + 1:
                return i + 1

        return len(nums) + 1
